package ciphers;

import java.util.Scanner;

public class CipherClient {
	static Scanner keyboard = new Scanner(System.in);

	public static void main (String [] args) {
		start(); 
	}

	//STARTERS
	private static void startEncryption() {
		System.out.println("What type of encryption would you like to do?"); 
		System.out.println("Choices are: caesar cipher, caesarian shift, ROT13, keyword cipher, substitution cipher"); 
		String response = keyboard.nextLine().toLowerCase(); 

		switch (response) {
		case "caesar cipher": {
			startCaesarCipher(); 
			break; 
		}
		case "caesarian shift": {
			startCaesarianShift(); 
			break; 
		}
		case "rot13": {
			startROT13(); 
			break; 
		}
		case "keyword cipher": {
			startKeywordCipher(); 
			break; 
		}
		case "substitution cipher": {
			startSubCipher(); 
			break; 
		}
		default: {
			System.out.println("Sorry, I didn't get that. Please try again.");
			startEncryption(); 
		}
		}
	}
	private static void startDecryption() {
		System.out.println("Would you like to encrypt a string before decrypting it? Y/N"); 
		String answer = keyboard.nextLine().toLowerCase(); 
		
		if (answer.equals("y")) {
			startEncryption(); 
		}
		else {
			System.out.println("Okay! Let's get started! "); 
		}
		
		System.out.println("What type of encryption is on the string you wish to decrypt?"); 
		System.out.println("This utility can decrypt: caesar cipher, caesarian shift, ROT13, keyword cipher"); 
		String response = keyboard.nextLine().toLowerCase(); 
		
		switch (response) {
		case "caesar cipher": {
			decryptCaesarCipher(); 
			break; 
		}
		case "caesarian shift": {
			decryptCaesarianShift(); 
			break; 
		}
		case "rot13": {
			decryptROT13(); 
			break; 
		}
		case "keyword cipher": {
			decryptKeywordCipher(); 
			break; 
		}
		case "substitution cipher": {
			decryptSubCipher(); 
			break;
		}
		default : {
			System.out.println("Sorry, I didn't quite get that. Please try again."); 
			startDecryption(); 
		}
		}
	}
	private static void start() {
		System.out.println("What would you like to do? (encrypt or decrypt?)"); 
		String response = keyboard.nextLine().toLowerCase();

		switch (response) {
		case "encrypt": {
			startEncryption(); 
			break;
		}
		case "decrypt": {
			startDecryption(); 
			break; 
		}
		default: {
			System.out.println("Sorry, I didn't get that. Please try again. "); 
			start(); 
		}
		}
	}
		
	//ENCRYPTION STARTERS
	private static void startSubCipher() {
		System.out.println("What string do you want to encrypt? "); 
		String str = keyboard.nextLine(); 
		System.out.println("substitution cipher: " + Cipher.substitutionCipher(str)); 
	}

	private static void startKeywordCipher() {
		System.out.println("What do you want to encrypt your string with? "); 
		String key = keyboard.nextLine(); 
		System.out.println("What string do you want to encrypt? "); 
		String str = keyboard.nextLine(); 
		System.out.println("keyword cipher: " + Cipher.keywordCipher(key, str)); 
	}

	private static void startROT13() {
		System.out.println("What string do you want to encrypt? "); 
		String str = keyboard.nextLine(); 
		System.out.println("ROT13: " + Cipher.ROT13(str)); 
	}

	private static void startCaesarianShift() {
		System.out.println("how much do you want to switch? "); 
		int length = Integer.parseInt(keyboard.nextLine()); 
		System.out.println("What string do you want to encrypt? "); 
		String str = keyboard.nextLine(); 
		System.out.println("caesarian shift: " + Cipher.caesarianShift(length, str)); 
	}

	private static void startCaesarCipher() {
		System.out.println("how much do you want to switch? "); 
		int length = Integer.parseInt(keyboard.nextLine()); 
		System.out.println("what string do you want to encrypt? "); 
		String str = keyboard.nextLine(); 
		System.out.println("caesar cipher: " + Cipher.caesarCipher(length, str)); 
	}

	//DECRYPTION STARTERS	
	private static void decryptSubCipher() {
		System.out.println("Sorry, substitution ciphers are virtually uncrackable. Good luck trying to crack that!"); 
	}
	private static void decryptKeywordCipher() {
		System.out.println("What was the keyword used to encrypt your string?"); 
		String key = keyboard.nextLine(); 
		System.out.println("What is the encrypted string? "); 
		String str = keyboard.nextLine(); 
		System.out.println("keyword deciper: " + Cipher.decryptKeywordCipher(key, str)); 
	}
	private static void decryptROT13() {
		System.out.println("What is the encrypted string?"); 
		String str = keyboard.nextLine(); 
		System.out.println("ROT13 decipher: " + Cipher.decryptROT13(str)); 
	}
	private static void decryptCaesarianShift() {
		System.out.println("what was the shift applied to the encrypted word?"); 
		int length = Integer.parseInt(keyboard.nextLine()); 
		System.out.println("what is the encrypted string?"); 
		String str = keyboard.nextLine(); 
		System.out.println("caesarian shift decipher: " + Cipher.decryptCaesarShift(length, str)); 
	}
	private static void decryptCaesarCipher() {
		System.out.println("what was the shift applied to the encrypted word?"); 
		int length = Integer.parseInt(keyboard.nextLine()); 
		System.out.println("what is the encrypted string?"); 
		String str = keyboard.nextLine(); 
		System.out.println("caesar decipher: " + Cipher.decryptCaesarCipher(length, str)); 
	}
}
